import {
  Controller,
  Post,
  Body,
  ClassSerializerInterceptor,
  UseInterceptors,
  UseGuards,
  Req,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { ApiOperation, ApiBody, ApiTags, ApiResponse } from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';
import { Request } from 'express';
import { AuthInterceptor } from './interceptor/auth.interceptor';

@Controller('auth')
@UseInterceptors(ClassSerializerInterceptor)
@ApiTags('登录')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('/login')
  @ApiOperation({ summary: '登录' })
  @ApiBody({ type: CreateAuthDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: Object,
  })
  @UseInterceptors(AuthInterceptor)
  async create(@Body() createAuthDto: CreateAuthDto) {
    return this.authService.signing(createAuthDto);
  }

  // 获取用户信息
  @UseGuards(JwtGuard)
  getHeaderToken(@Req() req: Request) {
    return req.user;
  }
}
